package kr.kwakyc.puzzle;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

public class Tile extends JPanel{
	
	private BufferedImage currentImage;
	private BufferedImage solutionImage;
	private ImagePanel imagePanel;
	
	private int currentX, currentY;

	public Tile(BufferedImage image) {
		this.currentImage = image;
		this.solutionImage = image;
		
		addMouseListener();
	}


	@Override
	public void paint(Graphics g) {
		g.drawImage(currentImage, 0, 0, this);
	}
	
	public void setImage(BufferedImage image){
		this.currentImage = image;
	}
	
	public void setSolutionImage(BufferedImage image){
		this.solutionImage = image;
	}
	
	public BufferedImage getImage(){
		return this.currentImage;
	}
	
	public void setImagePanel(ImagePanel imagePanel){
		this.imagePanel = imagePanel;
	}
	
	public void setCurrentLocation(int x, int y){
		this.currentX = x;
		this.currentY = y;
	}
	
	public int getCurrentLocationX(){
		return this.currentX;
	}
	
	public int getCurrentLocationY(){
		return this.currentY;
	}
	
	
	private void addMouseListener() {
		addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent arg0) {
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
			}
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				imagePanel.tileClicked(currentX, currentY);
			}
		});
	}


	public boolean isRight() {
		if(currentImage == solutionImage)	return true;
		else 								return false;
	}
}
